package ac.manchester.cs.afzal.term_classifier.main;

import java.io.*;
import java.util.Vector;

import ac.manchester.cs.afzal.term_classifier.information_retrieval.*;
import ac.manchester.cs.afzal.term_classifier.nlp.*;
import ac.manchester.cs.afzal.term_classifier.terms_sentence_handler.*;
import ac.manchester.cs.afzal.term_classifier.term_similarities.*;
import ac.manchester.cs.afzal.term_classifier.miscellaneous.*;

public class Main
{

    public static void main(String[] args)
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String input;
        try
        {
            System.out.println(
                    "*****************************************************");
            System.out.print(
                    "Please Choose among following options:\n" +
                    " 3. Clists to lst files generator \n" +
                    " 3a. Terms Extractor from CLISTS \n" +
                    " 4. Named Entity Tagging and Sentence Splitting (using GATE) \n" +
                    " 5. Sentence Splitter for each Term Occurrence \n" +
                    " 5a. Sentence Splitter for Disease Name Occurrences from GAD \n" +
                    " 5b. Sentence Splitter for Disease Name Occurrences from OBM \n" +
                    " 9. Map Terms to their Occurrences \n" +
                    " 6. Parse Sentences to PENN and CollapsedDependency \n" +
                    " 7. Convert PENN to XML \n" +
                    " 8. Stemmer  \n" +

                    " 9a.Load Seed Terms into Term Table (Term basis seed terms) \n" +

                    " 10.Context Builder \n" +
                    " 10a.Context Builder for Diseases GAD \n" +

                    " 11.Context Similarity Calculator \n" +
                    " 11a.Context Similarity Calculator for Diseases GAD \n" +

                    " 12.Lexical Similarity Calculator \n" +
                    " 12a. Lexical Comparison with Diseases Names \n" +

                    " 13.Combined Similarity Calculator \n" +
                    " 14.test lexcial profile \n" +
                    " 15.Derive Distinct Sentences and populate the table 'Distinct Sentences' \n" +
                    " 16.Map Sentences to Distinct Sentences (populate the table 'Sentence_Mapping' \n" +
                    " 17.Download Distinct Sentences \n" +
                    " Enter number to continue or 'e' to exit : ");
            input = in.readLine();
            input = input.trim();

            if(input.equals("1")) // obsoleted
            {
                Download_Documents download_documents = new Download_Documents();
                download_documents.read_search_result();
                download_documents.download_pmcids("bmc_ids.txt");
            }
            else if(input.equals("2")) // obsoleted
            {
                Parse_PMC_XML parse_XML = new Parse_PMC_XML();
                parse_XML.convert_pmc_xml_to_text();
            }
            else if(input.equals("3")) // used 7-02-12
            {
                Occurrences_Generator_Impl lst_generator = new Occurrences_Generator_Impl();
                lst_generator.lst_files_generator();
            }
            else if(input.equals("3a")) // used 7-02-12
            {
                Terms_Generator_Impl terms_generator = new Terms_Generator_Impl();
                terms_generator.terms_extractor();
            }

            else if(input.equals("4")) // used 7-02-12
            {
                Term_Lookup_Impl term_lookup = new Term_Lookup_Impl();
                term_lookup.term_lookup_and_sentence_boundry_mark(true);
            }
            else if(input.equals("5")) // used 7-02-12
            {
                Sentence_Splitter_Impl sentence_splitter = new Sentence_Splitter_Impl();
                sentence_splitter.countering_lookup();
            }
            else if(input.equals("5a")) // used 7-02-12
            {
                Sentence_Splitter_Impl sentence_splitter = new Sentence_Splitter_Impl();
                sentence_splitter.countering_lookup_for_diease_gad();
            }

            else if(input.equals("5b")) // used 23-07-12
            {
                Sentence_Splitter_OBM sentence_splitter = new Sentence_Splitter_OBM();
                sentence_splitter.countering_lookup();
            }

            else if(input.equals("9"))
            {
                Term_Mapping_Impl term_mapping = new Term_Mapping_Impl();
                term_mapping.terms_mapping(""); // other argument option is "unified_terms"
            }

            else if(input.equals("6"))
            {
                Parser_Single_Thread_Impl parse_sentences = new Parser_Single_Thread_Impl();
                parse_sentences.txt_to_penn_dep();
            }

            else if(input.equals("7"))
            {
                XML_Tree_Generator_Impl tree_conversion = new XML_Tree_Generator_Impl();
                tree_conversion.convert_penn_to_xml();
            }
            else if(input.equals("8"))
            {
                Stemming_Impl stemmer = new Stemming_Impl();
                stemmer.populate_stems_table();
            }
            else if(input.equals("9a"))
            {
                Term_Mapping_Impl term_mapping = new Term_Mapping_Impl();
                term_mapping.loadSeedTerms();
            }
            else if(input.equals("10"))
            {
                Context_Builder_Impl context_builder = new Context_Builder_Impl();
                long start = System.currentTimeMillis();
                context_builder.building_contexts();
                long elapsedTimeMillis = System.currentTimeMillis() - start;
                float elapsedTimeSec = elapsedTimeMillis / 1000F;
                System.out.println("Time Elapsed during Processing of 10 Documents: " + elapsedTimeSec + " secs");

            }
            else if(input.equals("10a"))
            {
                Context_Builder_Diseases_GAD context_builder = new Context_Builder_Diseases_GAD();
                context_builder.building_contexts();
            }
            else if(input.equals("11"))
            {
                Contextual_Similarity_Impl consim = new Contextual_Similarity_Impl();
                consim.contextual_similarity();
            }
            else if(input.equals("11a"))
            {
                Comparison_Contextual_Diseases_GAD consim = new Comparison_Contextual_Diseases_GAD();
                consim.contextual_similarity();
            }

            else if(input.equals("12"))
            {
                Lexical_Similarity_Impl lex = new Lexical_Similarity_Impl();
            }
            else if(input.equals("12a"))
            {
                Comparison_Lexical comparison_lexical = new Comparison_Lexical();
            }

            else if(input.equals("13"))
            {
                Combined_Similarity_Impl combined_similarity = new Combined_Similarity_Impl();
            }
            else if(input.equals("14"))
            {
                Lexical_Profile_Impl lpb = new Lexical_Profile_Impl();
                String[] str =
                {
                    "multiple", "sequence", "alignment"
                };
                Vector profile = lpb.term_profiles(str);
                System.out.println("Profile : " + profile.toString());
            }
            else if(input.equals("15"))
            {
                Distinct_Sentence_Mapping_Impl der_dis_sen = new Distinct_Sentence_Mapping_Impl();
                der_dis_sen.populate_distinct_sentences();
            }
            else if(input.equals("16"))
            {
                Distinct_Sentence_Mapping_Impl sm = new Distinct_Sentence_Mapping_Impl();
                sm.sentence_mapping();
            }
            else if(input.equals("17"))
            {
                Distinct_Sentence_Mapping_Impl der_dis_sen = new Distinct_Sentence_Mapping_Impl();
                der_dis_sen.download_distinct_sentences();
            }
            else if(input.equals("t"))
            {
                Term_Head_Extractor t_h = new Term_Head_Extractor();
            }
            else if(input.equals("e"))
            {
                System.exit(1);
            }
        }
        catch (Exception ex)
        {
            System.out.println(
                    "Value of Exception in reading input is : " + ex.getMessage());
        }
    }
}